package interest

import (
	"context"
	"fmt"
	"github.com/golang/protobuf/ptypes/empty"
	"selfService/兴趣相关/dao"
	"selfService/兴趣相关/models"
	"time"
)


type InterestService struct {}

func (this *InterestService)GetAllInterest(context.Context, *empty.Empty) (*Interestlist, error)  {
	interest_colloct_dao := &dao.Interest_colloct_dao{}
	result := []*Interest{}
	for _,i := range *interest_colloct_dao.GetAll(){
		result = append(result, &Interest{
			Id: i.Id,
			InterestName: i.Interest_name,
		})
	}
	fmt.Println("输出结果")
	fmt.Println(result)
	return &Interestlist{
		Intrslist: result,
	},nil

}

func (this *InterestService)InsertInterest(c context.Context,i *Interest) (*InterestReponse, error)  {
	mod := &models.Interest_collect{};
	mod.Id = i.Id
	mod.Interest_name = i.InterestName
	mod.CreateTime = time.Now()
	mod.UpdateTime = time.Now()
	interest_colloct_dao := &dao.Interest_colloct_dao{}
	result := interest_colloct_dao.Insert(mod)
	return &InterestReponse{
		Result: result,
	},nil
}

func (this *InterestService)ChangeInterest(c context.Context,i *InterestRequest) (*InterestReponse, error)  {
	interest_colloct_dao := &dao.Interest_colloct_dao{}
	result := interest_colloct_dao.UpdateInterest(i.Id,i.ChangeName)
	return &InterestReponse{
		Result: result,
	},nil
}

//根据id  删除某个兴趣（管理员）
func (this *InterestService)DeleteInterestById(c context.Context, re *UserInterMidRquest) (*ChangeInterestResponse, error)  {
	Interest_colloct_dao := &dao.Interest_colloct_dao{}
	result := Interest_colloct_dao.DeleteInterest(re.Id)
	x := ""
	if result==true {
		x = "成功"
	}else {
		x = "失败"
	}
	return &ChangeInterestResponse{
		State: x,
	},nil
}
